package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.ConstantUserInfo;
import com.llkj.qingnianguoxue.base.MyApplication;
import com.llkj.qingnianguoxue.bean.CircleListBean;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 全部成员
 */
public class CircleMemberAdapter extends BaseQuickAdapter<CircleListBean.CircleBean, BaseViewHolder> {

    public CircleMemberAdapter(int layoutResId, List<CircleListBean.CircleBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CircleListBean.CircleBean item) {
        ImageLoadingUtil.loadingImg((ImageView) baseViewHolder.getView(R.id.iv_head), item.getUserpic(),0);
        baseViewHolder.setText(R.id.tv_name, item.getUsername());


        TextView tvAddFriend = baseViewHolder.getView(R.id.tv_add_friend);
        ImageView ivChat = baseViewHolder.getView(R.id.iv_chat);

        // 是否是好友 1 好友  2 待确认（发起方） 3 待确认（接收方） 4 不是好友
        String uid = MyApplication.getInstance().sputil.getString(ConstantUserInfo.USER_ID);
        if(uid.equals(item.getId())){
            tvAddFriend.setVisibility(View.GONE);
            ivChat.setVisibility(View.GONE);
        }else{
            if (1==item.getIs_friend()) {//好友
                tvAddFriend.setVisibility(View.GONE);
                ivChat.setVisibility(View.VISIBLE);
            } else if (2==item.getIs_friend()){//
                ivChat.setVisibility(View.GONE);
                tvAddFriend.setVisibility(View.VISIBLE);
                tvAddFriend.setText("已请求");
            }else if (3==item.getIs_friend()){//
                ivChat.setVisibility(View.GONE);
                tvAddFriend.setVisibility(View.VISIBLE);
                tvAddFriend.setText("待确认");
            }else{
                ivChat.setVisibility(View.GONE);
                tvAddFriend.setVisibility(View.VISIBLE);
                tvAddFriend.setText("添加好友");
            }
        }

        baseViewHolder.addOnClickListener(R.id.tv_add_friend);
        baseViewHolder.addOnClickListener(R.id.iv_chat);
    }

}
